package com.g.ocache.utils;

/**
 * 
 * @author Jingqi Xu
 */
public final class ComparatorUtils {

	/**
	 * 
	 * @param <T>
	 * @param t1
	 * @param t2
	 * @param asc
	 * @param nullsAreHigh
	 * @return
	 */
	public static final <T extends Comparable<T>> int compareTo(T t1, T t2, boolean asc, boolean nullsAreHigh) {
		//
		int r = 0;
		if(t1 == null && t2 == null) {
			r = 0;
		} else if(t1 == null) {
			r = nullsAreHigh ? 1 : -1;
		} else if(t2 == null) {
			r = nullsAreHigh ? -1 : 1;
		} else {
			r = t1.compareTo(t2);
		}
		
		//
		return asc ? r : -r;
	}
}
